<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2019 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 小夏 < 449134904@qq.com>
// +----------------------------------------------------------------------
namespace app\admin\controller;

use cmf\controller\AdminBaseController;
use think\Db;
use app\admin\model\AdminMenuModel;

class StonePostController extends AdminBaseController
{

    protected $customerId =0;
    protected $tombId =0;
    protected $tomb_type =0;
    protected $result_list =0;

    public function initialize()
    {
        parent::initialize();

    }



	public function index(){

        if ($this->customerId==0){
            return $this->fetch('login');
        }
        switch ($this->tomb_type) {
            case 1:
                return $this->fetch('index_commodity');
                break;
            case 2:
                return $this->fetch('index_arl');
                break;
            case 3:
                return $this->fetch('index_ecological');
                break;
            case 4:
                return $this->fetch('index_festival');
                break;
        }

		return $this->fetch('shouindex');
	}
	/*落葬业务*/
	public function burial(){
         if ($this->request->post()){
             $param = $this->request->param();
             $deceased = $param['deceased'];
             $order_id = $param['order_id'];
             $customer_id = $param['customer_id'];
             $tomb_id = $param['tomb_id'];
             $tomb_num = $param['tomb_num'];
             $handle = $param['handle'];
             $handle_id = $handle['handle_id'];
             unset($handle['handle_id']);
             if ($handle_id){

             }else{
                 $handle['handle_is_sms'] = isset($handle['handle_is_sms'])?$handle['handle_is_sms']:0;
                 $handle['tomb_id'] = $tomb_id;
                 $handle['add_time'] = time();
                 $handle_id = Db::name('deceased_handle')->insertGetId($handle);
             }

             foreach ($deceased as $key=>&$value){
                 $deceased_id = $value['deceased_id'];
                 unset($value['deceased_id']);
                 $value['order_id'] = $order_id;
                 $value['date_funeral'] = $value['funeral_time'];
                 $value['add_time'] = time();
                 $value['order_id'] = $order_id;
                 $value['tomb_id'] = $tomb_id;
                 $value['tomb_num'] = $tomb_num;
                 $value['customer_id'] = $customer_id;
                 $value['handle_id'] = $handle_id;
                 if ($deceased_id){
                     $deceased_list = Db::name('archives_deceased')->where(['deceased_id'=>$deceased_id])->update($value);
                 }else{
                     if ($value['deceased_name']) {
                         $deceased_list = Db::name('archives_deceased')->insertGetId($value);
                         $deceased_id = $deceased_list;
                     }
                 }
             }
             return $this->success('提交成功',url("Stone/chooseGoods",['order_id'=>$order_id,'customer_id'=>$customer_id,'tomb_id'=>$tomb_id]));
         }
        if ($this->tomb_type==2){

            return $this->fetch('art');
        }else{

            $deceased_list = Db::name('archives_deceased')->where(['tomb_id'=>$this->result_list['tomb_id'],'customer_id'=>$this->customerId])->select();
            $this->assign('deceased',$deceased_list);
        }
		return $this->fetch();
	}

	public function chooseGoods(){

    }
	/*缴费打证*/
	public function prints(){
        if ($this->customerId==0){
            return $this->fetch('login');
        }
        $this->assign([
            'result'=>$this->result_list
        ]);
		return $this->fetch();
	}
	/*维保业务*/
	public function maintenance(){
        if ($this->customerId==0){
            return $this->fetch('login');
        }
		return $this->fetch();
	}
	/*迁墓业务*/
	public function move(){
        if ($this->customerId==0){
            return $this->fetch('login');
        }
		return $this->fetch();
	}
	/*艺术墓*/
	public function art(){
        if ($this->customerId==0){
            return $this->fetch('login');
        }
		return $this->fetch();
	}
	/*寄存业务*/
	public function check(){
        if ($this->customerId==0){
            return $this->fetch('login');
        }
		return $this->fetch();
	}
	/*退墓业务*/
	public function back(){
        if ($this->customerId==0){
            return $this->fetch('login');
        }
		return $this->fetch();
	}
	/*管理费业务*/
	public function manage(){
        if ($this->customerId==0){
            return $this->fetch('login');
        }
		return $this->fetch();
	}
	/*证件管理业务*/
	public function paperwork(){
        if ($this->customerId==0){
            return $this->fetch('login');
        }
		return $this->fetch();
	}
	public function paperloss(){
        if ($this->customerId==0){
            return $this->fetch('login');
        }
		return $this->fetch();
	}
	/*墓碑刻制*/
	public function carve(){
        if ($this->customerId==0){
            return $this->fetch('login');
        }
		return $this->fetch();
	}
	/*工程首页*/
	public function sale(){
        if ($this->customerId==0){
            return $this->fetch('login');
        }
		return $this->fetch();
	}
	/*墓位产品信息*/
	public function add(){
        $parentid = $this->request->param('parentid', 0, 'intval');
        $id = $this->request->param('tid', 0, 'intval');
        $this->assign("id",$id);
        $this->assign("parentid",$parentid);
		return $this->fetch();
	}
}